﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace TileEngine
{
    class Background
    {
        List<Cloud> clouds = new List<Cloud>();
        public int cloudMax=50;
        public Background()
        {
            for (int i = 0; i < 30; i++)
            {
                clouds.Add(new Cloud());
                clouds.Last().randomizeLocation();
            }
        }
        public Background(int startingCloud)
        {
            for (int i = 0; i < startingCloud; i++)
            {
                clouds.Add(new Cloud());
                clouds.Last().randomizeLocation();
            }
        }
        public void update() {
            for (int i = clouds.Count - 1; i>-1 ; i--)
            {
                if(clouds[i].isOut())
                    clouds.RemoveAt(i);
            }
            if (clouds.Count < cloudMax)//bunu birden yükseltirsen çok seksi oluyor
            {
                clouds.Insert(Global.myRandom.Next() % clouds.Count, new Cloud());
            }
            for (int i = 0; i < clouds.Count; i++)
            {
                clouds[i].update();
            }     
        }
        public void draw(SpriteBatch spriteBatch)
        {
            int cTime = Global.currentWorld.gameTime;
            int gTime = Global.gameTime;
            Vector2 pos = new Vector2((cTime % (gTime / 2)) *
                                (Camera.screenDimension.X + 500) / (gTime / 2) - 500, Camera.screenDimension.Y / 10);
            if (Global.currentWorld.gameTime<Global.gameTime/2)
            {
                spriteBatch.Draw(Textures.sun,pos,Color.White);
            }
            else
            {
                spriteBatch.Draw(Textures.moon,pos, Color.White);
            }
            for (int i = 0; i < clouds.Count; i++)
            {
                clouds[i].draw(spriteBatch);
            }
        }
    }
}
